package com.anysoft.web;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.webkit.WebView;

import com.anysoft.base.BaseWebviewWithCacheActivity;
import com.anysoft.event.TimeOutEvent;
import com.anysoft.utils.CommonUtil;
import com.anysoft.utils.MentorLogger;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * Created by wwq on 2017/4/8.
 * 在线客服页面
 */

public class OnlineCustomerActivity extends BaseWebviewWithCacheActivity {
    private String titleStr;

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        isShowTitleBar(true);
        loadUrl = getIntent().getStringExtra("loadUrl");
        titleStr = getIntent().getStringExtra("title");
        title.setText(titleStr);
        if (CommonUtil.isNetWorkConnected(mActivity)) {
            initView(loadUrl);
        }
    }

    public void onshouldOverrideUrlLoadingCallBack(WebView webview, String url) {
        MentorLogger.Log(TAG, "url=" + url);
        if (url.contains("prompt.html")) {
            mIntent.setClass(mActivity, SelectWarmPromptActivity.class);
            mIntent.putExtra("url", url);
            startActivity(mIntent);
        } else {
            webview.loadUrl(url);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onTimeOutCallBack(TimeOutEvent event) {
        if (event.isSuccess) {
            finish();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
